package com.avic.rong.adapter.show;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.avic.rong.R;
import com.avic.rong.bean.show_bean.ChannelContent;
import com.avic.rong.bean.show_bean.EsInfoBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by TSJ-2018-0492 on 2019/8/9.
 */

public class ChannedAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private LayoutInflater inflater;
    private ArrayList<ChannelContent> bean;
    private Context context;
    private int TYPE_0 = 0, TYPE_1 = 1, TYPE_2 = 2, TYPE_3 = 3, TYPE_4 = 4, TYPE_5 = 5, TYPE_6 = 6, TYPE_7 = 7, TYPE_8 = 8;
    private List<ChannelContent.DataBean> data;
    private ArrayList<EsInfoBean> esInfoBeans;

    public ChannedAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setBean(ArrayList<ChannelContent> bean) {
        this.bean = bean;
//        notifyDataSetChanged();
    }

    public void setEsInfoBeans(ArrayList<EsInfoBean> esInfoBeans) {
        this.esInfoBeans = esInfoBeans;
//        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view;
        if (i == TYPE_0) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        } else if (i == TYPE_2) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        } else if (i == TYPE_3) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        } else if (i == TYPE_4) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        BigRecommecdViewHolder holder = (BigRecommecdViewHolder) viewHolder;


        int itemViewType = getItemViewType(i);
        if (bean != null) {
            if (bean.get(i) != null) {
                switch (itemViewType) {
                    case 0:
                        data = bean.get(i).getDataX();
                        ChannedTextAdapter followAdapter = new ChannedTextAdapter(context);
                        followAdapter.setData(data);
                        holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
                        holder.roofplacement_rec.setAdapter(followAdapter);
                        break;
                    case 2:
                        data = bean.get(i).getDataX();
                        ChannedTextAdapter followAdapter1 = new ChannedTextAdapter(context);
                        followAdapter1.setData(data);
                        followAdapter1.setEsInfoBeans(esInfoBeans);
                        holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
                        holder.roofplacement_rec.setAdapter(followAdapter1);
                        break;
                    case 3:
                        data = bean.get(i).getDataX();
                        ChannedTextAdapter followAdapter2 = new ChannedTextAdapter(context);
                        followAdapter2.setData(data);
                        holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
                        holder.roofplacement_rec.setAdapter(followAdapter2);
                        break;
                    default:
                        return;
                }

            }
        } else {
            Toast.makeText(context, "数据空", Toast.LENGTH_LONG).show();
        }

//        if (type+""!=null&& data !=null){
//            if (type==TYPE_1){
//                ChannedTextAdapter followAdapter = new ChannedTextAdapter(context);
//                followAdapter.setData(data);
//                holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
//                holder.roofplacement_rec.setAdapter(followAdapter);
//                holder.roofplacement_rec.addItemDecoration(divider);
//            }else if (type==TYPE_2){
//                ChannedTextAdapter followAdapter = new ChannedTextAdapter(context);
//                followAdapter.setData(data);
//                holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
//                holder.roofplacement_rec.setAdapter(followAdapter);
//                holder.roofplacement_rec.addItemDecoration(divider);
//            }else if (type==TYPE_3){
//                ChannedTextAdapter followAdapter = new ChannedTextAdapter(context);
//                followAdapter.setData(data);
//                holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
//                holder.roofplacement_rec.setAdapter(followAdapter);
//                holder.roofplacement_rec.addItemDecoration(divider);
//            }
//        }else{
//            Toast.makeText(context,"数据空",Toast.LENGTH_LONG).show();
//        }


    }

    @Override
    public int getItemCount() {
        int count = 0;
        if (bean != null) {
//        for (int i = 0; i <bean.size() ; i++) {
//            if (bean.get(i)!=null){
//                count++;
//            }
//        }

            return bean.size();
        }
        return 0;
    }

    @Override
    public int getItemViewType(int position) {
        if (bean != null) {
            if (bean.get(position) != null) {
                int type = bean.get(position).getType();
                switch (type) {
                    case 2:
                        return TYPE_2;
                    case 1:
                        return TYPE_0;
                    case 3:
                        return TYPE_3;

                }
            }
        }

        return super.getItemViewType(position);
    }
}
